package model

import "auth/model/entity"

type DeptCreateRequest struct {
	DeptName string `json:"dept_name" binding:"required"`

	ParentId int64 `json:"parent_id" binding:"required"`

	Sort int `json:"sort"`
}

type DeptUpdateRequest struct {
	DeptId int64 `json:"dept_id" binding:"required"`

	DeptName string `json:"dept_name" binding:"required"`

	Sort int `json:"sort"`

	ParentId *int64 `json:"parent_id" binding:"required"`
}

type DeptListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	DeptId int64 `json:"dept_id" validate:"required"`

	DeptName string `json:"dept_name" validate:"required"`
}

type DeptListResponse struct {
	Total int         `json:"total"`
	Data  []*DeptInfo `json:"data"`
}

type GetDeptListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`
}

type GetDeptExcludeRequest struct {
	DeptId int64 `json:"dept_id" binding:"required"`
}

type GetDeptListResponse struct {
	Total int         `json:"total"`
	Data  []*DeptInfo `json:"data"`
}

type GetDeptExcludeResponse struct {
	Data []*DeptInfo `json:"data"`
}

type DeptInfo struct {
	DeptId int64 `json:"dept_id"`

	DeptName string `json:"dept_name"`

	ParentId int64 `json:"parent_id"`

	Sort int `json:"sort"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`

	Children []*DeptInfo `json:"children" gorm:"-"`
}

type DeptDeleteRequest struct {
	ID int64 `json:"id"  binding:"required"`
}

func DeptsEntityToDto(depts []*entity.Dept) []*DeptInfo {
	out := make([]*DeptInfo, 0, len(depts))
	for _, c := range depts {
		out = append(out, DeptEntityToDto(c))
	}
	return out
}

func DeptEntityToDto(e *entity.Dept) *DeptInfo {
	return &DeptInfo{

		DeptId: e.DeptId,

		DeptName: e.DeptName,

		ParentId: e.ParentId,

		Sort: e.Sort,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
